#include "GLVertexArray.h"

GLVertexArray::GLVertexArray()
{
	glGenVertexArrays(1, &name);
}

GLVertexArray::~GLVertexArray()
{
	glDeleteVertexArrays(1, &name);
}

void GLVertexArray::attach(GLBuffer* buffer, GLuint index, GLint size, GLenum type)
{
	attach(buffer->target, buffer, index, size, type);
}

void GLVertexArray::attach(GLenum target, GLBuffer* buffer, GLuint index, GLint size, GLenum type)
{
	glBindVertexArray(name);
	glBindBuffer(target, buffer->name);
	if (target != GL_ELEMENT_ARRAY_BUFFER)
	{
		glEnableVertexAttribArray(index);
		glVertexAttribPointer(index, size, type, GL_FALSE, 0, NULL);
	}
	glBindVertexArray(0);
}